package com.ce.pms.renovation.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.ce.pms.base.service.impl.PmsBaseServiceImpl;
import com.ce.pms.charge.model.BusinessCodeDomain;
import com.ce.pms.charge.service.IBusinessCodeService;
import com.ce.pms.charge.service.INonConventionalChargeService;
import com.ce.pms.charge.service.IParameterDefService;
import com.ce.pms.charge.vo.ChargeRecordVO;
import com.ce.pms.charge.vo.ParameterDefVO;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.util.BigDecimalUtil;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.renovation.dao.IDepositAccountingDao;
import com.ce.pms.renovation.dao.IInspectionRequisitionDao;
import com.ce.pms.renovation.dao.IPassChargeItemDao;
import com.ce.pms.renovation.dao.IPassDao;
import com.ce.pms.renovation.dao.IRenovateChargeItemDao;
import com.ce.pms.renovation.dao.IRenovateLicenceDao;
import com.ce.pms.renovation.dao.IRenovateRequisitionDao;
import com.ce.pms.renovation.dao.IRenovateViolationDao;
import com.ce.pms.renovation.model.AbstractChargeItemDO;
import com.ce.pms.renovation.model.AbstractViolationDO;
import com.ce.pms.renovation.model.DepositAccountingDO;
import com.ce.pms.renovation.model.InspectionRequisitionDO;
import com.ce.pms.renovation.model.PassChargeItemDO;
import com.ce.pms.renovation.model.PassDO;
import com.ce.pms.renovation.model.RenovateChargeItemDO;
import com.ce.pms.renovation.model.RenovateLicenceDO;
import com.ce.pms.renovation.model.RenovateRequisitionDO;
import com.ce.pms.renovation.service.IRenovateChargeService;
import com.ce.pms.renovation.vo.DepositAccountingListVO;
import com.ce.pms.renovation.vo.DepositAccountingQueryVO;
import com.ce.pms.renovation.vo.DepositAccountingVO;
import com.ce.pms.renovation.vo.RenovateChargeItemVO;
import com.ce.pms.system.renovation.dao.IPassChargeItemConfigDao;
import com.ce.pms.system.renovation.dao.IRenovateChargeItemConfigDao;
import com.ce.pms.system.renovation.model.PassChargeItemConfigDO;
import com.ce.pms.system.renovation.model.RenovateChargeItemConfigDO;
import com.ce.util.BeanUtil;
import com.sitechasia.webx.core.support.Page;

/**
 * 装修费用服务类
 */
public class RenovateChargeServiceImpl extends PmsBaseServiceImpl implements IRenovateChargeService{

	//定义程序中用到的中文常量
	private static final String ADD_AMERCEMENT = "补收罚款";

	private static final String ADD_COMPANY_AMERCEMENT = "补收装修商装修罚款";

	private static final String ADD_OWNER_AMERCEMENT = "补收业主装修罚款";

	private static final String DE = "的";

	private static final String IN = "收";

	private static final String OFFSET_COMPANY_AMERCEMENT = "抵冲装修商装修罚款";

	private static final String OFFSET_DEPOSIT = "押金抵冲";

	private static final String OFFSET_OWNER_AMERCEMENT = "抵冲业主装修罚款";

	private static final String PASS_IN = "出入证：收";

	private static final String PASS_RETURN = "出入证：退";

	private static final String RETURN_COMPANY_DEPOSIT = "退回装修商保证金";

	private static final String RETURN_DEPOSIT = "退回业主保证金";

	private IBusinessCodeService businessCodeService;
	private IDepositAccountingDao depositAccountingDao;
	private IInspectionRequisitionDao inspectionRequisitionDao;
	private INonConventionalChargeService nonConventionalChargeService;
	private IParameterDefService parameterDefService;
	private IPassChargeItemConfigDao passChargeItemConfigDao;
	private IPassChargeItemDao passChargeItemDao;
	private IPassDao passDao;
	private IRenovateChargeItemConfigDao renovateChargeItemConfigDao;
	private IRenovateChargeItemDao renovateChargeItemDao;
	private IRenovateLicenceDao renovateLicenceDao;
	private IRenovateRequisitionDao  renovateRequisitionDao;
	private IRenovateViolationDao renovateViolationDao;

   /**
	 * 功能描述:保证金核算，将首先查询保证金，如果有，则修改；如果没有则新增<br>
	 * 装修进程进入：退保证金
	 * @param depositAccountingVO
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-31<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public DepositAccountingVO countDepositAndAmercement(DepositAccountingVO depositAccountingVO) {
		DepositAccountingDO depositAccountingDO = null;
		if (depositAccountingVO.getKeyword() != null) {
			depositAccountingDO = depositAccountingDao.findById(depositAccountingVO.getKeyword());
		}
		if (null == depositAccountingDO)
			depositAccountingDO = new DepositAccountingDO();

		assembleDepositAccountingV2D(depositAccountingVO, depositAccountingDO);
		depositAccountingDO.setDepositDate(this.getDate());

		if (null == depositAccountingDO.getKeyword()) {
			InspectionRequisitionDO inspect = getInspectRequistionDo(depositAccountingVO);
			depositAccountingDO.setInspectionRequisitionDO(inspect);
			depositAccountingDO.setSysInfo(this.createInfo(depositAccountingVO.getCreateId()));
			depositAccountingDao.saveObject(depositAccountingDO);
		} else {
			this.modifyInfo(depositAccountingDO.getSysInfo(), depositAccountingVO.getCreateId());
		}

		depositAccountingDO.setHandleYn(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);
		depositAccountingDO.getInspectionRequisitionDO().getRenovateLicence().getRenovateRequisition().setProcessState(
				SysrefcodeDO.RM_RENOVATE_PROCESS_STATE_RET);

		// notifyAddApproveDepositAccountingChargerecord(depositAccountingDO.getKeyword(),
		// depositAccountingVO.getCreateId());

		return assembleDepositAccountingD2V(depositAccountingDO);
	}

	/**
	 * 功能描述:删除指定出入证的收费项目，首先将删除对应的费用记录<br>
	 * 注：只有有一项费用已经处理，将都不能进行删除操作
	 *
	 * @param passId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-29<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public Boolean deletePassChargeItem(Long passId) {
		List<PassChargeItemDO> passChargeItemList = passChargeItemDao.getPassChargeItemByPassId(passId);
		checkChargeHandleState(passChargeItemList);

		for (PassChargeItemDO item : passChargeItemList) {
			deleteChargeRecordByBiz(item.getKeyword(), SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_CARD_C);
			passChargeItemDao.deleteObject(item);
		}

		return true;
	}

	/**
	 * 功能描述:删除指定出入证且费用业务类型为出入证退证的费用记录<br>
	 * 注：退证的费用记录bizId和收费的费用记录bizId一样，但业务类型不一样
	 * @param passId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-29<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	   public Boolean deletePassChargeRecord(Long passId){
		   PassDO passDo= passDao.findById(passId);

		   List<Long> bizIds = getPassDepositChargeRecordIds(passId);

		   checkPassDepositIsHandle(bizIds,passDo);

		   //删除
		   for(Long id : bizIds){
			   deleteChargeRecordByBiz(id,SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_CARD_R);
		   }

		   return true;
	   }

	   /**
	    * 功能描述:删除指定装修申请的收费项目，首先将删除对应的费用记录<br>
	    * @param renovateRequisitionId
	    * @return<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-25<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   public Boolean deleteRenovateChargeItem(RenovateRequisitionDO renovateRequisition){
		   for(RenovateChargeItemDO item : renovateRequisition.getRenovateChargeItemDOSet()){
			   deleteChargeRecordByBiz(item.getKeyword(),SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_REN);
			   renovateChargeItemDao.deleteObject(item);
		   }
		   return true;
	   }

	   /**
	    * 功能描述:删除指定装修申请的收费项目未处理的费用记录,但不删除收费项目本身<br>
	    * @param renovateRequisitionId
	    * @return<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-25<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   public Boolean deleteRenovateChargeRecord(RenovateRequisitionDO renovateRequisition){
		   for(RenovateChargeItemDO item : renovateRequisition.getRenovateChargeItemDOSet()){
			   deleteChargeRecordByBiz(item.getKeyword(),SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_REN);
		   }
		   return true;
	   }

	   /**
	    * 功能描述:修改收费项目,如果费用状态为免收，将删除其对应的费用记录<br>
	    * @param renovateChargeItems<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-26<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   public void editRenovateChargeItems(Long requisitionId,List<RenovateChargeItemVO> renovateChargeItems){
		   RenovateRequisitionDO requistion=renovateRequisitionDao.findById(requisitionId);
		   for(RenovateChargeItemVO item : renovateChargeItems){
			   RenovateChargeItemDO renovateChargeItemDO=editRenovateChargeItem(item);

			   if( SysrefcodeDO.RM_FEE_STATE_ESC.equals( renovateChargeItemDO.getFeeState()) ){
				   deleteChargeRecordByBiz(renovateChargeItemDO.getKeyword(),SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_REN);
			   }else{
				   ChargeRecordVO chargeRecord = getChargeRecordByBiz(renovateChargeItemDO.getKeyword());
				   if(null==chargeRecord){
					   addChargeRecord(requistion, renovateChargeItemDO,null);
				   }
			   }

		   }
	//	   List<RenovateChargeItemDO> itemList=renovateChargeItemDao.getRenovateChargeItemListByRequisitionId(requisitionId);

		   requistion.setFeeState(getFeeState(requistion.getRenovateChargeItemDOSet()));
	   }

	   /**
	    * 功能描述:查询指定许可证的保证金补退核算记录，如果没有将进行统计<br>
	    * @param licenceId
	    * @return<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-30<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   public DepositAccountingVO getDepositAccounting(Long licenceId){
		   DepositAccountingDO deposit=depositAccountingDao.getDepositAccountings(licenceId);
		   DepositAccountingVO depositAccountingVO=new DepositAccountingVO();

		   //保证金的计算
		   RenovateLicenceDO licence=renovateLicenceDao.findById(licenceId);
		   List<AbstractViolationDO> violationList=renovateViolationDao.getViolationsByLicenceId(licenceId);
			// 计算
		   BigDecimal companyDeposit=calculateDeposit(licence.getRenovateRequisition(),SysrefcodeDO.RM_RENOVATE_CHARGE_COMPANY);
		   BigDecimal ownerDeposit = calculateDeposit(licence.getRenovateRequisition(),SysrefcodeDO.RM_RENOVATE_CHARGE_OWNER);
		   BigDecimal ownerSum = calculateAmercementOwner(violationList);
		   BigDecimal companySum =calculateAmercementCompany(violationList);

		   if( null != deposit){
			   depositAccountingVO=assembleDepositAccountingD2V(deposit);
		   }
		   depositAccountingVO.setClientAmercementCount(ownerSum);
		   depositAccountingVO.setCompanyAmercementCount(companySum);
		   depositAccountingVO.setCompanyDeposit(companyDeposit);
		   depositAccountingVO.setClientDeposit(ownerDeposit);
		   depositAccountingVO.setLicenceId(licenceId);

		   return depositAccountingVO;
	   }

	   /**
	    * 功能描述:查询指定许可证的保证金补退核算记录，如果没有将返回null<br>
	    * @param licenceId
	    * @return<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-30<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   public DepositAccountingVO getDepositAccountingBylicenceId(Long licenceId){
		   DepositAccountingDO deposit=depositAccountingDao.getDepositAccountings(licenceId);

		   if( null==deposit)return null;

		   return assembleDepositAccountingD2V(deposit);
	   }

	/**
	 * 功能描述:将旧的装修申请的所有装修收费的收费项目挂靠在新的装修申请上<br>
	 * @param oldRequisitionId
	 * @param newRequisitionId<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void moveRenovateChargeItemToNewQuistion(Long oldRequisitionId,Long newRequisitionId){
		List<RenovateChargeItemDO> itemList=renovateChargeItemDao.getRenovateChargeItemListByRequisitionId(oldRequisitionId);
		for(RenovateChargeItemDO item : itemList){
			item.setRenovateRequisition(new RenovateRequisitionDO(newRequisitionId));
		}
	}

   /**
    * 功能描述:通知保证金审批通过<br>
    * 向费用模块抛帐</br>
    * @param depositAccountingId
    * @param createor<br>
    * Create author:罗军林<br>
    * Create on:2009-1-7<br>
    * Edit author:<br>
    * Edit on:<br>
    * Why:<br>
    */
   public void notifyAddApproveDepositAccountingChargerecord(Long depositAccountingId,Long createor) {
	   checkParameterIsNull(depositAccountingId, "renovate:renovate_deposit_count_id_not_null");
	   DepositAccountingDO depositAccounting=depositAccountingDao.findById(depositAccountingId);
	   addOwnerCharge(createor, depositAccounting);
	   addCompanyCharge(createor,depositAccounting);
	}

	/**
	 * 功能描述:重算费用<br>
	 * 1）修改费用项目的费用
	 * 2) 删除该装修申请尚未处理的费用记录
	 * 3）重新向费用记录抛帐
	 * 4) 如果有与装修面积相关的收费且已经有一项已经收费,将抛出异常
	 * 5) 如果有与装修面积无关的收费且已经收费,费用记录不产生
	 * @param renovateRequisitionId<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-25<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	   public void notifyRecalculateFee(Long renovateRequisitionId){
		  RenovateRequisitionDO renovateRequisitionDO= renovateRequisitionDao.findById(renovateRequisitionId);

		  boolean result = isChargeItemAsAreaHandle(renovateRequisitionDO);
		  if(result){
			  throw new BusinessException("renovate:renovate_edit_area_err",BusinessException.ERROR);
		  }

		   deleteRenovateChargeRecord(renovateRequisitionDO);

		   for(RenovateChargeItemDO item : renovateRequisitionDO.getRenovateChargeItemDOSet()){
			   item.setSum(item.calculateFee());
			   if(!SysrefcodeDO.RM_FEE_STATE_IN.equals(item.getFeeState())){
			     addChargeRecord(renovateRequisitionDO, item, null);
			   }
		   }
	   }

	/**
	 * 功能描述:与装修面积相关的费用是否有处理的,如果有将返回true<br>
	 * @param renovateRequisitionDO
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-21<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private boolean isChargeItemAsAreaHandle(RenovateRequisitionDO renovateRequisitionDO) {
		   for(RenovateChargeItemDO item : renovateRequisitionDO.getRenovateChargeItemDOSet()){
			   if(SysrefcodeDO.RM_RENOVATE_CHARGE_MODE_SIZE.equals(item.getItemConfig().getChargeMode())
					   && SysrefcodeDO.RM_FEE_STATE_IN.equals(item.getFeeState())){
				   return true;
			   }
		   }
		return false;
	}

	   /**
	    * 功能描述:通知增加收费项目及费用记录<br>
	    * @param passId<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-29<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   public void notifyRegisterPassCharge(Long passId){
		   PassDO passDo=passDao.findById(passId);
		   List<PassChargeItemConfigDO> passChargeItemList=passChargeItemConfigDao.getAllPassChargeItemConfigs();
		   if( null==passChargeItemList || passChargeItemList.size()==0 ){
			   throw new BusinessException("renovate:renovate_pass_charge_item_is_none",BusinessException.ERROR);
		   }
		   for(PassChargeItemConfigDO item : passChargeItemList){
			   PassChargeItemDO passChargeItem=addPassChargeItem(passDo,item);
			   if(null!=passChargeItem){
				   addChargeRecord(passDo.getRenovateLicence().getRenovateRequisition(), passChargeItem, passDo.getName());
			   }
		   }
	   }

	   /**
	    * 功能描述:通知登记装修收费<br>
	    * @param renovateRequisitionId<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-24<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   public void notifyRegisterRenovateCharge(Long renovateRequisitionId){
		   RenovateRequisitionDO renovateRequistion= renovateRequisitionDao.findById(renovateRequisitionId);
		   checkParameterIsNull(renovateRequistion, "renovate:renovate_requisition_is_null");
		   List<RenovateChargeItemConfigDO> renovateChargeItemList=renovateChargeItemConfigDao.getAllRenovateChargeItemConfigs();
		   checkRenovateChargeItemConfigList(renovateChargeItemList);
		   for(RenovateChargeItemConfigDO itemConfig : renovateChargeItemList){
			   RenovateChargeItemDO renovateChargeItem = addRenovateChargeItem(renovateRequistion,itemConfig);
			   addChargeRecord(renovateRequistion,  renovateChargeItem,null);
		   }
	   }

	   /**
	    * 功能描述:通知退证<br>
	    * 费用记录增加一笔业务类型为出入证，操作类型为退证的费用记录
	    * @param passId<br>
	    * Create author:罗军林<br>
	    * Create on:2009-1-11<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   public void notifyReturnPassCharge(Long passId){
		   PassDO passDo=passDao.findById(passId);
		   if( SysrefcodeDO.RM_FEE_STATE_NO.equals(passDo.getChargeFeeState()) ) return;
		   List<PassChargeItemDO> passChargeItemList = renovateLicenceDao.getPassChargeItemDOs(passId);
		   for(PassChargeItemDO item : passChargeItemList){
				   Long businessId=getBusinessId(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_CODE);
				   if( businessId.equals(item.getItemConfig().getBusinessCode().getKeyword())){
					   addReturnPassChargeRecord(passDo.getRenovateLicence().getRenovateRequisition(), item, passDo.getName());
					   }
		   }
	   }

	   /**
	    * 功能描述:保证金查询<br>
	    * @param queryCondition
	    * @return<br>
	    * Create author:罗军林<br>
	    * Create on:2009-1-6<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   public Page queryDepositAccountings(DepositAccountingQueryVO queryCondition){
		   Page page = depositAccountingDao.queryDepositAccountings(queryCondition);
		   List<DepositAccountingListVO> result=page.getResult();
		   for(DepositAccountingListVO item : result){
			   SysrefcodeDO approvalState = sysrefcodeDao.getSysrefCodesByCode(
					   SysrefcodeDO.RM_DEPOSIT_ACCOUNTING_APPROVAL_STATE_CODE, item.getApprovalState());
			   item.setApprovalStateView(approvalState==null ? null : approvalState.getName());
			   if( SysrefcodeDO.CONSTANTS_DIGITAL_ONE.equals(item.getFeeState()) ){
				   item.setFeeStateView("完成");
			   }else{
				   item.setFeeStateView("未完成");
			   }
		   }
		return page;
	   }




	/**
	 * 功能描述:批量更新装修收费项目费费用状态<br>
	 * @param houseId 将根据房号修改该房间的装修申请状态<br>
	 * @param chargeItemIds<br>
	 * @param feeState
	 * Create author:罗军林<br>
	 * Create on:2009-1-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void updateRenovateChargeItemFeeState(Long houseId,List<Long> chargeItemIds,String feeState) {
		RenovateRequisitionDO requisitionDO=renovateRequisitionDao.getRenovateRequisitionDOByHouseId(houseId);
		for(Long id : chargeItemIds){
			RenovateChargeItemDO renovateChargeItemDO = renovateChargeItemDao.findById(id);
			renovateChargeItemDO.setFeeState(feeState);
		}
		requisitionDO.setFeeState(getFeeState(requisitionDO.getRenovateChargeItemDOSet()));
	}

	/**
	 * 功能描述:添加一笔费用记录<br>
	 * @param renovateRequistion
	 * @param itemConfig
	 * @param renovateChargeItem<br>
	 * @param chageObject 收费主体名称，用于备注信息
	 * Create author:罗军林<br>
	 * Create on:2008-12-25<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void addChargeRecord(RenovateRequisitionDO renovateRequistion,AbstractChargeItemDO chargeItem,String chageObject){
		ChargeRecordVO chargeRecord = null;
		if( chargeItem instanceof RenovateChargeItemDO){
			chargeRecord=assembleChargeRecord(renovateRequistion, (RenovateChargeItemDO)chargeItem);
		}else if( chargeItem instanceof PassChargeItemDO){
			chargeRecord=assembleChargeRecord(renovateRequistion, (PassChargeItemDO)chargeItem,chageObject);
		}
		addNonChargeRecordToDB(chargeRecord);
	}

	/**
	 * 功能描述:向数据库添加一笔非常规费用记录<br>
	 * 注: <br>
	 * 1)如果费用金额为零,将忽略 <br>
	 * @param chargeRecord<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-21<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void addNonChargeRecordToDB(ChargeRecordVO chargeRecord) {
		if(null!=chargeRecord || BigDecimal.ZERO.compareTo(chargeRecord.getSum()) != 0){
			nonConventionalChargeService.addChargeRecord(chargeRecord);
		}else{
			logger.info("有一项收费项目被过忽略");
		}
	}


	/**
	 * 功能描述:添加装修商类费用（三类）<br>
	 * 补收装修商金额，操作类型:物业费，项目名称：补收罚款 备注：补收装修商装修罚款 交易码：RENOVATE_AMERCEMENT_CODE中查找<br>
	 * 装修商罚款，操作类型:押金抵冲，项目名称：押金抵冲 备注：抵冲装修商装修罚款 交易码：DEPOSIT_PAY_CODE中查找<br>
	 * 退回装修商保证金，操作类型:押金返还，项目名称：退回装修商保证金 备注：退回装修商保证金 交易码：DEPOSIT_CODE中查找<br>
	 * @param createor
	 * @param depositAccounting<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void addCompanyCharge(Long createor, DepositAccountingDO depositAccounting) {
		//向收费记录入帐
		if(  BigDecimalUtil.isBigZero(depositAccounting.getCompanyAddedAmercement()) ){
			//补收装修商金额，操作类型:物业费，项目名称：补收罚款 备注：补收装修商装修罚款 交易码：RENOVATE_AMERCEMENT_CODE中查找
			ChargeRecordVO chargeRecordVO = createChargeRecordVo(createor, depositAccounting);
			chargeRecordVO.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_PROPERTY);
			chargeRecordVO.setItemName(ADD_AMERCEMENT);
			chargeRecordVO.setRemark(ADD_COMPANY_AMERCEMENT);
			chargeRecordVO.setSum(depositAccounting.getCompanyAddedAmercement());
			chargeRecordVO.setBusinessId( getBusinessId(SysrefcodeDO.PARAMETER_DEF_RENOVATE_AMERCEMENT_CODE) );
			addNonChargeRecordToDB(chargeRecordVO);
		}
		if( BigDecimalUtil.isBigZero(depositAccounting.getCompanyAmercement()) ){
			//装修商罚款，操作类型:押金抵冲，项目名称：押金抵冲 备注：抵冲装修商装修罚款 交易码：DEPOSIT_PAY_CODE中查找
			//如果罚款>押金,抵冲金额=押金;否则抵冲金额=罚款
			BigDecimal sum=null;//抵冲金额
			ChargeRecordVO chargeRecordVO = createChargeRecordVo(createor, depositAccounting);
			chargeRecordVO.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_DEPOSIT_AGA);
			chargeRecordVO.setItemName(OFFSET_DEPOSIT);
			chargeRecordVO.setRemark(OFFSET_COMPANY_AMERCEMENT);
			chargeRecordVO.setBusinessId(getBusinessId(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_PAY_CODE));
			BigDecimal deposit=calculateDeposit(depositAccounting.getInspectionRequisitionDO().getRenovateLicence()
					.getRenovateRequisition()
					, SysrefcodeDO.RM_RENOVATE_CHARGE_COMPANY);
			if(depositAccounting.getCompanyAmercement().compareTo(deposit)>0){
				sum=deposit;
			}else{
				sum=depositAccounting.getCompanyAmercement();
			}
			chargeRecordVO.setSum(sum);
			addNonChargeRecordToDB(chargeRecordVO);
		}
		if( BigDecimalUtil.isBigZero(depositAccounting.getReturnCompanyDeposit()) ){
			//退回装修商保证金，操作类型:押金返还，项目名称：退回装修商保证金 备注：退回装修商保证金 交易码：DEPOSIT_CODE中查找
			ChargeRecordVO chargeRecordVO = createChargeRecordVo(createor, depositAccounting);
			chargeRecordVO.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_RETURNDEPOSIT);
			chargeRecordVO.setItemName(RETURN_COMPANY_DEPOSIT);
			chargeRecordVO.setRemark(RETURN_COMPANY_DEPOSIT);
			chargeRecordVO.setBusinessId(getBusinessId(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_CODE));
			chargeRecordVO.setSum(depositAccounting.getReturnCompanyDeposit());
			addNonChargeRecordToDB(chargeRecordVO);
		}
	}

	/**
	 * 功能描述:添加业主类费用（三类）<br>
	 * 补收业主金额，操作类型:物业费，项目名称：补收罚款 备注：补收业主装修罚款 交易码：RENOVATE_AMERCEMENT_CODE中查找<br>
	 * 业主罚款，操作类型:押金抵冲，项目名称：押金抵冲 备注：抵冲业主装修罚款 交易码：DEPOSIT_PAY_CODE中查找<br>
	 * 退回业主保证金，操作类型:押金返还，项目名称：退回业主保证金 备注：退回业主保证金 交易码：DEPOSIT_CODE中查找<br>
	 * @param createor
	 * @param depositAccounting<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void addOwnerCharge(Long createor, DepositAccountingDO depositAccounting) {
		//向收费记录入帐
		if(  BigDecimalUtil.isBigZero(depositAccounting.getClientAddedAmercement()) ){
			//补收业主金额，操作类型:物业费，项目名称：补收罚款 备注：补收业主装修罚款 交易码：RENOVATE_AMERCEMENT_CODE中查找
			ChargeRecordVO chargeRecordVO = createChargeRecordVo(createor, depositAccounting);
			chargeRecordVO.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_PROPERTY);
			chargeRecordVO.setItemName(ADD_AMERCEMENT);
			chargeRecordVO.setRemark(ADD_OWNER_AMERCEMENT);
			chargeRecordVO.setSum(depositAccounting.getClientAddedAmercement());
			chargeRecordVO.setBusinessId( getBusinessId(SysrefcodeDO.PARAMETER_DEF_RENOVATE_AMERCEMENT_CODE) );
			addNonChargeRecordToDB(chargeRecordVO);
		}
		if( BigDecimalUtil.isBigZero(depositAccounting.getClientAmercement()) ){
			//业主罚款，操作类型:押金抵冲，项目名称：押金抵冲 备注：抵冲业主装修罚款 交易码：DEPOSIT_PAY_CODE中查找
			//如果罚款>押金,抵冲金额=押金;否则抵冲金额=罚款
			BigDecimal sum=null;//抵冲金额
			ChargeRecordVO chargeRecordVO = createChargeRecordVo(createor, depositAccounting);
			chargeRecordVO.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_DEPOSIT_AGA);
			chargeRecordVO.setItemName(OFFSET_DEPOSIT);
			chargeRecordVO.setRemark(OFFSET_OWNER_AMERCEMENT);
			chargeRecordVO.setBusinessId(getBusinessId(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_PAY_CODE));
			BigDecimal deposit=calculateDeposit(depositAccounting.getInspectionRequisitionDO().getRenovateLicence()
					.getRenovateRequisition()
					, SysrefcodeDO.RM_RENOVATE_CHARGE_OWNER);
			if(depositAccounting.getClientAmercement().compareTo(deposit)>0){
				sum=deposit;
			}else{
				sum=depositAccounting.getClientAmercement();
			}
			chargeRecordVO.setSum(sum);
			addNonChargeRecordToDB(chargeRecordVO);
		}
		if( BigDecimalUtil.isBigZero(depositAccounting.getReturnClientDeposit()) ){
			//退回业主保证金，操作类型:押金返还，项目名称：退回业主保证金 备注：退回业主保证金 交易码：DEPOSIT_CODE中查找
			ChargeRecordVO chargeRecordVO = createChargeRecordVo(createor, depositAccounting);
			chargeRecordVO.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_RETURNDEPOSIT);
			chargeRecordVO.setItemName(RETURN_DEPOSIT);
			chargeRecordVO.setRemark(RETURN_DEPOSIT);
			chargeRecordVO.setBusinessId(getBusinessId(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_CODE));
			chargeRecordVO.setSum(depositAccounting.getReturnClientDeposit());
			addNonChargeRecordToDB(chargeRecordVO);
		}
	}

//	/**
//	 * 功能描述:根据参数预设，设置操作类型(出入证)<br>
//	 * 操作类型仅有：物业收费和押金收费
//	 * 改动：只要判断是否为押金，否则都为物业费
//	 * @param renovateChargeItem
//	 * @param chargeRecord<br>
//	 * Create author:罗军林<br>
//	 * Create on:2009-1-4<br>
//	 * Edit author:<br>
//	 * Edit on:<br>
//	 * Why:<br>
//	 */
//	private void setOperationType(PassChargeItemDO passChargeItemDO, ChargeRecordVO chargeRecord) {
//		if( getBusinessId(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_CODE).equals(chargeRecord.getBusinessId())){
//			chargeRecord.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_DEPOSIT);//押金收费
//		}else{
//			chargeRecord.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_PROPERTY);//工收费
//		}
//	}

	   /**
	    * 功能描述:新增出入证收费项目<br>
	    * 注:如果收费项目为零,将急略,并返回null
	    * @param passdo
	    * @param renovateChargeItemConfigDO
	    * @return<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-29<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   private PassChargeItemDO addPassChargeItem(PassDO passdo, PassChargeItemConfigDO passChargeItemConfigDO){
		   PassChargeItemDO passChargeItem=new PassChargeItemDO();
		   passChargeItem.setFeeState(SysrefcodeDO.RM_FEE_STATE_NO);
		   passChargeItem.setItemConfig(passChargeItemConfigDO);
		   passChargeItem.setSum(passChargeItem.calculateFee());
		   passChargeItem.setPass(passdo);
		   if(BigDecimal.ZERO.compareTo(passChargeItem.getSum())!=0){
			   passChargeItemDao.saveObject(passChargeItem);
		   }else{
			   passChargeItem=null;
		   }

		   return passChargeItem;
	   }


	/**
	    * 功能描述:新增装修收费项目<br>
	    * 费用为零的将忽略,并返回NULL <br>
	    * @param renovateRequistion
	    * @param renovateChargeItemConfigDO<br>
	    * @return
	    * Create author:罗军林<br>
	    * Create on:2008-12-24<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   private RenovateChargeItemDO addRenovateChargeItem(RenovateRequisitionDO renovateRequistion, RenovateChargeItemConfigDO renovateChargeItemConfigDO){
		   RenovateChargeItemDO renovateChargeItem=new RenovateChargeItemDO();
		   renovateChargeItem.setFeeState(SysrefcodeDO.RM_FEE_STATE_NO);
		   renovateChargeItem.setItemConfig(renovateChargeItemConfigDO);
		   //注：必须先关联装修申请，才能计算
		   renovateChargeItem.setRenovateRequisition(renovateRequistion);
		   renovateChargeItem.setSum(renovateChargeItem.calculateFee());
		   if(BigDecimal.ZERO.compareTo(renovateChargeItem.getSum())!=0){
			   renovateChargeItemDao.saveObject(renovateChargeItem);
		       return renovateChargeItem;
	       }else{
	    	   return null;
	       }
	   }

	/**
	    * 功能描述:增加一个退出入证操作的费用记录<br>
	    * @param renovateRequistion
	    * @param passChargeItem
	    * @param chargeObject<br>
	    * Create author:罗军林<br>
	    * Create on:2009-1-11<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   private void addReturnPassChargeRecord(RenovateRequisitionDO renovateRequistion,PassChargeItemDO passChargeItem,String chargeObject){
			ChargeRecordVO chargeRecord=new ChargeRecordVO();
			chargeRecord.setBizId(passChargeItem.getKeyword());
			chargeRecord.setBizModule(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN);
			chargeRecord.setBizType(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_CARD_R);

			chargeRecord.setItemName(passChargeItem.getItemConfig().getItemName());
			StringBuffer remark=new StringBuffer();
			remark.append(PASS_RETURN).append(chargeObject).append(DE).append(chargeRecord.getItemName());
			chargeRecord.setRemark(remark.toString());

			chargeRecord.setHouseId(renovateRequistion.getHouse().getKeyword());
			chargeRecord.setHouseNumber(renovateRequistion.getHouse().getHouseNumber());
			chargeRecord.setCreator(renovateRequistion.getSysInfo().getCreator());
			chargeRecord.setSum(passChargeItem.getItemConfig().getPrice());

			chargeRecord.setBusinessId( getBusinessId(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_PAY_CODE));
			BusinessCodeDomain businessCode = businessCodeService.getBusinessCodeDomainById(chargeRecord.getBusinessId());
			chargeRecord.setBizCode(businessCode.getBizCode());

			chargeRecord.setEnterAccountMethod(passChargeItem.getItemConfig().getEnterAccountMethod());
			chargeRecord.setHandleYn(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);

			chargeRecord.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_RETURNDEPOSIT);

			addNonChargeRecordToDB(chargeRecord);
	   }

   /**
 * 功能描述:出入证费用项目的装配<br>
 * @param renovateRequistion
 * @param renovateChargeItem
 * @return<br>
 * Create author:罗军林<br>
 * Create on:2008-12-25<br>
 * Edit author:<br>
 * Edit on:<br>
 * Why:<br>
 */
private ChargeRecordVO assembleChargeRecord(RenovateRequisitionDO renovateRequistion, PassChargeItemDO passChargeItem,String chageObject) {

	ChargeRecordVO chargeRecord=new ChargeRecordVO();
	chargeRecord.setBizId(passChargeItem.getKeyword());
	chargeRecord.setBizModule(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN);
	chargeRecord.setBizType(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_CARD_C);

	chargeRecord.setItemName(passChargeItem.getItemConfig().getItemName());
	StringBuffer remark=new StringBuffer();
	remark.append(PASS_IN).append(chageObject).append(DE).append(chargeRecord.getItemName());
	chargeRecord.setRemark(remark.toString());

	chargeRecord.setHouseId(renovateRequistion.getHouse().getKeyword());
	chargeRecord.setHouseNumber(renovateRequistion.getHouse().getHouseNumber());
	chargeRecord.setCreator(renovateRequistion.getSysInfo().getCreator());
	chargeRecord.setSum(passChargeItem.getSum());

	chargeRecord.setBusinessId(passChargeItem.getItemConfig().getBusinessCode().getKeyword());
	chargeRecord.setBizCode(passChargeItem.getItemConfig().getBusinessCode().getBizCode());

	chargeRecord.setEnterAccountMethod(passChargeItem.getItemConfig().getEnterAccountMethod());
	chargeRecord.setHandleYn(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);

	setOperationType(chargeRecord);


	return chargeRecord;
}

	/**
	 * 功能描述:装修费用项目的装配<br>
	 * @param renovateRequistion
	 * @param renovateChargeItem
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-25<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private ChargeRecordVO assembleChargeRecord(RenovateRequisitionDO renovateRequistion, RenovateChargeItemDO renovateChargeItem) {
		ChargeRecordVO chargeRecord=new ChargeRecordVO();

		chargeRecord.setBizId(renovateChargeItem.getKeyword());
		chargeRecord.setBizModule(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN);
		chargeRecord.setBizType(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_REN);
		chargeRecord.setItemName(renovateChargeItem.getItemConfig().getItemName());

		SysrefcodeDO chargeObject= sysrefcodeDao.getSysrefCodesByCode(SysrefcodeDO.RM_RENOVATE_CHARGE_CODE,
				renovateChargeItem.getItemConfig().getChargeObject());
		StringBuffer remark=new StringBuffer();
		remark.append(IN)
		.append(chargeObject.getName())
		.append(DE)
		.append(renovateChargeItem.getItemConfig().getItemName());
		chargeRecord.setRemark(remark.toString());

		chargeRecord.setHouseId(renovateRequistion.getHouse().getKeyword());
		chargeRecord.setHouseNumber(renovateRequistion.getHouse().getHouseNumber());
		chargeRecord.setCreator(renovateRequistion.getSysInfo().getCreator());
		chargeRecord.setSum(renovateChargeItem.getSum());

		chargeRecord.setBusinessId(renovateChargeItem.getItemConfig().getBusinessCode().getKeyword());
		chargeRecord.setBizCode(renovateChargeItem.getItemConfig().getBusinessCode().getBizCode());

		chargeRecord.setEnterAccountMethod(SysrefcodeDO.FEE_CHARGE_RECORD_ENTER_ACCOUNT_METHOD_DIRECT);
		chargeRecord.setHandleYn(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);

		setOperationType(chargeRecord);

		return chargeRecord;
	}

	/**
	    * 功能描述:<br>
	    * @param depositAccountingDO
	    * @return<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-31<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   private DepositAccountingVO assembleDepositAccountingD2V(DepositAccountingDO depositAccountingDO){
		   DepositAccountingVO depositAccountingVO=new DepositAccountingVO();
		   BeanUtil.convertVoAsDo(depositAccountingDO, depositAccountingVO);
		   depositAccountingVO.setApprovalState(depositAccountingDO.getApprovalState());
		   depositAccountingVO.setClientAddedAmercement(depositAccountingDO.getClientAddedAmercement());//补收业主金额
		   depositAccountingVO.setClientFactAmercement(depositAccountingDO.getClientAmercement());//业主罚款
		   depositAccountingVO.setCompanyAddedAmercement(depositAccountingDO.getCompanyAddedAmercement());//补收装修商金额
		   depositAccountingVO.setCompanyFactAmercement(depositAccountingDO.getCompanyAmercement());//装修商罚款
		   depositAccountingVO.setReturnClientDeposit(depositAccountingDO.getReturnClientDeposit());//退业主金额
		   depositAccountingVO.setReturnCompanyDeposit(depositAccountingDO.getReturnCompanyDeposit());//退装修商金额
		   depositAccountingVO.setLicenceId(depositAccountingDO.getInspectionRequisitionDO().getRenovateLicence().getKeyword());//许可证ID
		   return depositAccountingVO;
	   }



   /**
    * 功能描述:<br>
    * @param depositAccountingVO
    * @param depositAccountingDO<br>
    * Create author:罗军林<br>
    * Create on:2008-12-31<br>
    * Edit author:<br>
    * Edit on:<br>
    * Why:<br>
    */
   private void assembleDepositAccountingV2D(DepositAccountingVO depositAccountingVO, DepositAccountingDO depositAccountingDO){
	   BeanUtil.convertVoAsDo(depositAccountingVO, depositAccountingDO);
	   depositAccountingDO.setClientAddedAmercement(depositAccountingVO.getClientAddedAmercement());//补收业主金额
	   depositAccountingDO.setClientAmercement(depositAccountingVO.getClientFactAmercement());//业主罚款
	   depositAccountingDO.setCompanyAddedAmercement(depositAccountingVO.getCompanyAddedAmercement());//补收装修商金额
	   depositAccountingDO.setCompanyAmercement(depositAccountingVO.getCompanyFactAmercement());//装修商罚款
	   depositAccountingDO.setReturnClientDeposit(depositAccountingVO.getReturnClientDeposit());//退业主金额
	   depositAccountingDO.setReturnCompanyDeposit(depositAccountingVO.getReturnCompanyDeposit());//退装修商金额

	   depositAccountingDO.setApprovalState(SysrefcodeDO.RM_DEPOSIT_ACCOUNTING_APPROVAL_STATE_NEW);
	   depositAccountingDO.setHandleYn(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);
   }

	   /**
	 * 功能描述:<br>
	 * @param violationList
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-30<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private BigDecimal calculateAmercementCompany(List<AbstractViolationDO> violationList) {
		   BigDecimal companySum=BigDecimal.ZERO;
		   for(AbstractViolationDO item : violationList){
			   companySum=companySum.add(item.getAmerceCompany());
		   }
		return companySum;
	}

	/** 功能描述:<br>
	 * @param violationList
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-30<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private BigDecimal calculateAmercementOwner(List<AbstractViolationDO> violationList) {
		BigDecimal ownerSum=BigDecimal.ZERO;
		   for(AbstractViolationDO item : violationList){
			   ownerSum=ownerSum.add(item.getAmerceClient());
		   }
		return ownerSum;
	}

	/**
	 * 功能描述:根据收费对象计算保证金<br>
	 * @param requisition
	 * @param chargeObject
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-30<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private BigDecimal calculateDeposit(RenovateRequisitionDO requisition,String chargeObject) {
		BigDecimal deposit=BigDecimal.ZERO;
		   for(RenovateChargeItemDO item : requisition.getRenovateChargeItemDOSet()){
			   if( !SysrefcodeDO.RM_FEE_STATE_ESC.equals(item.getFeeState())
					   && chargeObject.equals( item.getItemConfig().getChargeObject()) ){
				  Long businessId = getBusinessId(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_CODE);
				  if(businessId!=null && businessId.equals(item.getItemConfig().getBusinessCode().getKeyword())){
					  deposit=deposit.add(item.getSum());
				  }
			   }
		   }
		return deposit;
	}

	/**
	 * 功能描述:检查对应的费用是否都未处理，如果有一项已经处理将抛出异常<br>
	 * @param passChargeItemList<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void checkChargeHandleState(List<PassChargeItemDO> passChargeItemList) {
		List<Long> bizIds=new ArrayList<Long>();
		   for(PassChargeItemDO item : passChargeItemList){
			   bizIds.add(item.getKeyword());
		   }
		   Boolean result = nonConventionalChargeService.checkFinishIsHandle(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN,
				   SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_CARD_C, bizIds);
		   if(!result){
			   throw new BusinessException("renovate:renovate_pass_chargeitem_handle",BusinessException.ERROR);
		   }
	}




	/**
	 * 功能描述:检查出入证的押金是否都已经处理，只要有一项已经处理将抛出异常<br>
	 * @param bizIds<br>
	 * @param passDo <br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-16<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void checkPassDepositIsHandle(List<Long> bizIds,PassDO passDo) {
		   boolean result=nonConventionalChargeService.checkFinishIsHandle(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN,
				   SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_CARD_R, bizIds);
		   if(!result){
			   throw new BusinessException("renovate:renovate_has_one_charge_handle,"+passDo.getPassNumber(),BusinessException.ERROR);
		   }
	}

	/**
	 * 功能描述:如果装修收费项目还没有设置，不能进行装修申请<br>
	 * @param renovateChargeItemList<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-12<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void checkRenovateChargeItemConfigList(List<RenovateChargeItemConfigDO> renovateChargeItemList) {
		if(renovateChargeItemList==null || renovateChargeItemList.size()==0){
			   throw new BusinessException("renovate:renovate_charge_item_none",BusinessException.ERROR);
		   }
	}

	/**
	 * 功能描述:创建收费记录VO<br>
	 * 下列值预设：
	 * <ol>
	 * <li>是否处理：否</li>
	 * <li>入帐方式：直接入帐</li>
	 * <li>房号ID：保证金核算的房间ID</li>
	 * <li>模块：装修</li>
	 * <li>业务类型：保证金核算</li>
	 * <li>业务ID：保证金核算ID</li>
	 * <li>创建人：传入的</li>
	 * </ol>
	 * <br>
	 * @param createor
	 * @param depositAccounting
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private ChargeRecordVO createChargeRecordVo(Long createor, DepositAccountingDO depositAccounting) {
		ChargeRecordVO chargeRecordVO = new ChargeRecordVO();
		chargeRecordVO.setHandleYn(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);
		chargeRecordVO.setEnterAccountMethod(SysrefcodeDO.FEE_CHARGE_RECORD_ENTER_ACCOUNT_METHOD_DIRECT);
		chargeRecordVO.setHouseId(depositAccounting.getInspectionRequisitionDO().getRenovateLicence().getRenovateRequisition().getHouse().getKeyword());
		chargeRecordVO.setBizModule(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN);
		chargeRecordVO.setBizType(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_DEPOSIT);
		chargeRecordVO.setBizId(depositAccounting.getKeyword());
		chargeRecordVO.setCreator(createor);
		return chargeRecordVO;
	}

	/**
	 * 功能描述:删除收费项目对应的费用记录<br>
	 * @param item<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-25<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void deleteChargeRecordByBiz(Long chargeItemId,String bizType) {
		boolean result=nonConventionalChargeService.deleteChargeRecordByBiz(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN,bizType, chargeItemId);
	//		   if(!result){
	//			   throw new BusinessException("删除费用记录出现异常");
	//		   }
	}

	   /**
	    * 功能描述:修改单个收费项目<br>
	    * @param renovateChargeItemVO<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-26<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   private RenovateChargeItemDO editRenovateChargeItem(RenovateChargeItemVO renovateChargeItemVO){
		   RenovateChargeItemDO renovateChargeItemDO=renovateChargeItemDao.findById(renovateChargeItemVO.getKeyword());
		   renovateChargeItemDO.setFeeState(renovateChargeItemVO.getFeeState());
		   renovateChargeItemDO.setRemark(renovateChargeItemVO.getRemark());
		   return renovateChargeItemDO;
	   }

	/**
	 * 功能描述:参数预设中的交易码ID，如果没有预设将抛出异常<br>
	 * @param code 参数预设CODE
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private Long getBusinessId(String code) {
		Long businessId = null;
		ParameterDefVO def= getParameterDef(code);
		businessId = (def==null) ? null : def.getPvalue();
		checkParameterIsNull(businessId, "renovate:renovate_parameter_business_not_null");
		return businessId;
	}

	/**
	 * 功能描述:参数预设中的交易码ID，如果没有预设将返回null<br>
	 * @param code 参数预设CODE
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private Long getBusinessIdNoExp(String code) {
		Long businessId = null;
		ParameterDefVO def= getParameterDef(code);
		businessId = (def==null) ? null : def.getPvalue();
		return businessId;
	}

	/**
	 * 功能描述:查询指定收费项目的费用记录<br>
	 * @param renovateChargeItemDO
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-5<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private ChargeRecordVO getChargeRecordByBiz(Long chargeItemId) {
		ChargeRecordVO chargeRecord=nonConventionalChargeService.getChargeRecordByBiz(
				   SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN,
				   SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_REN,
				   chargeItemId);
		return chargeRecord;
	}

	/**
	 * 功能描述:取得装修申请费用状态算法<br>
	 * @param itemList
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-4<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private String getFeeState(Set<RenovateChargeItemDO> itemList) {
		int stateNo = 0;// 未收
		int stateEsc = 0;// 免收
		int stateIn = 0;// 已收
		int stateReturn = 0;// 已退
		int size = itemList.size();// 总项目数
		String feeState = null;

		for (RenovateChargeItemDO item : itemList) {
			if (SysrefcodeDO.RM_FEE_STATE_NO.equals(item.getFeeState())) {
				stateNo++;
			} else if (SysrefcodeDO.RM_FEE_STATE_ESC.equals(item.getFeeState())) {
				stateEsc++;
			} else if (SysrefcodeDO.RM_FEE_STATE_IN.equals(item.getFeeState())) {
				stateIn++;
			} else if (SysrefcodeDO.RM_FEE_STATE_RETURN.equals(item
					.getFeeState())) {
				stateReturn++;
			}
		}

		if (stateNo > 0) {
			feeState = SysrefcodeDO.RM_FEE_STATE_NO;
		} else if (stateEsc == size) {
			feeState = SysrefcodeDO.RM_FEE_STATE_ESC;
		} else if ( stateReturn == size ){
			feeState = SysrefcodeDO.RM_FEE_STATE_RETURN;
		}else if ( (stateIn + stateEsc) == size
			|| (stateIn + stateReturn) == size ) {
			feeState = SysrefcodeDO.RM_FEE_STATE_IN;
		}
		return feeState;
	}

	private InspectionRequisitionDO getInspectRequistionDo(DepositAccountingVO depositAccountingVO) {
		InspectionRequisitionDO inspect= inspectionRequisitionDao.getInspectionRequisitionByLicenceId(depositAccountingVO.getLicenceId());
		return inspect;
	}

	/**
	 * 功能描述:<br>
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-4<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private ParameterDefVO getParameterDef(String code) {
		ParameterDefVO parameterDef = parameterDefService.findParameterDefByPkey(code);
		return parameterDef;
	}

	/**
	 * 功能描述:得到指定许可证的押金收费项目ID列表<br>
	 * @param passId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-16<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private List<Long> getPassDepositChargeRecordIds(Long passId) {
		List<PassChargeItemDO> passChargeItemList=passChargeItemDao.getPassChargeItemByPassId(passId);
		   //收集将要操作的收费记录ID
		   List<Long> bizIds=new ArrayList<Long>();
		   for(PassChargeItemDO item : passChargeItemList){
			   Long businesId = getBusinessId(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_CODE);
			   if(item.getItemConfig().getBusinessCode().getKeyword().equals(businesId)){
				   bizIds.add(item.getKeyword());
			   }
		   }
		return bizIds;
	}

	/**
	 * 功能描述:根据参数预设，设置操作类型（许可证，出入证）<br>
	 * 操作类型仅有：物业收费和押金收费
	 * 改动：不是押金就是物业费
	 * @param renovateChargeItem
	 * @param chargeRecord<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-4<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void setOperationType(ChargeRecordVO chargeRecord) {
		Long businessId=getBusinessIdNoExp(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_CODE);
		if( chargeRecord.getBusinessId().equals(businessId) ){
			chargeRecord.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_DEPOSIT);//押金收费
		}else {
			chargeRecord.setOperationType(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_PROPERTY);//物业收费
		}
	}


	public void setBusinessCodeService(IBusinessCodeService businessCodeService) {
		this.businessCodeService = businessCodeService;
	}

   public void setDepositAccountingDao(IDepositAccountingDao depositAccountingDao) {
	this.depositAccountingDao = depositAccountingDao;
}

   public void setInspectionRequisitionDao(
		IInspectionRequisitionDao inspectionRequisitionDao) {
	this.inspectionRequisitionDao = inspectionRequisitionDao;
}

   public void setNonConventionalChargeService(
		INonConventionalChargeService nonConventionalChargeService) {
	this.nonConventionalChargeService = nonConventionalChargeService;
}

   public void setParameterDefService(IParameterDefService parameterDefService) {
	this.parameterDefService = parameterDefService;
}

	public void setPassChargeItemConfigDao(
			IPassChargeItemConfigDao passChargeItemConfigDao) {
		this.passChargeItemConfigDao = passChargeItemConfigDao;
	}

   public void setPassChargeItemDao(IPassChargeItemDao passChargeItemDao) {
	this.passChargeItemDao = passChargeItemDao;
}

   public void setPassDao(IPassDao passDao) {
	this.passDao = passDao;
}


   public void setRenovateChargeItemConfigDao(
		IRenovateChargeItemConfigDao renovateChargeItemConfigDao) {
	this.renovateChargeItemConfigDao = renovateChargeItemConfigDao;
}

   public void setRenovateChargeItemDao(
		IRenovateChargeItemDao renovateChargeItemDao) {
	this.renovateChargeItemDao = renovateChargeItemDao;
}

	public void setRenovateLicenceDao(IRenovateLicenceDao renovateLicenceDao) {
		this.renovateLicenceDao = renovateLicenceDao;
	}

	public void setRenovateRequisitionDao(
			IRenovateRequisitionDao renovateRequisitionDao) {
		this.renovateRequisitionDao = renovateRequisitionDao;
	}

	public void setRenovateViolationDao(IRenovateViolationDao renovateViolationDao) {
		this.renovateViolationDao = renovateViolationDao;
	}

}
